//
//  NewMessageViewController.m
//  1gene
//
//  Created by 1jiyin on 16/3/15.
//  Copyright © 2016年 1jiyin. All rights reserved.
//
//*******************新消息界面*******************
#import "NewMessageViewController.h"

@interface NewMessageViewController ()<NewMessageDelegate>
@property(nonatomic,strong)NewMessageTableView *tableView;//有消息显示tableView
@property(nonatomic,strong)UIView *myView;//没有消息显示view
@end

@implementation NewMessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:[UIView new]];
    [self initData];
    [self createNavigation];
    [self createUI];
    // Do any additional setup after loading the view.
}
-(void)initData
{
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    [user setObject:@[@"123456"] forKey:@"test1Array"];
    [user synchronize];
}
-(void)createNavigation
{
    self.navigationController.navigationBar.barTintColor=[UIColor colorWithRed:84/255.0 green:199/255.0 blue:222/255.0 alpha:1];
    //返回
    UIButton *leftBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame=CGRectMake(0, 0, 25, 25);
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"left_back"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    
    //标题
    UILabel *title=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];
    title.text=@"新消息";
    title.font=[UIFont systemFontOfSize:22];
    title.textAlignment=NSTextAlignmentCenter;
    title.textColor=[UIColor whiteColor];
    self.navigationItem.titleView=title;
}
//返回上一页
-(void)leftBtnClick:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark 创建界面
-(void)createUI
{
    NSLog(@"新消息界面");
    NSInteger number=[_dataDic[@"total"] integerValue];
    if (number>0) {
        _tableView=[[NewMessageTableView alloc]initWithFrame:CGRectMake(0, 34, self.view.frame.size.width, self.view.frame.size.height-44) style:UITableViewStyleGrouped data:_dataDic];
        //_tableView.separatorColor=[UIColor redColor];
        _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        _tableView.myDelegate=self;
        [self.view addSubview:_tableView];
    }else{
        _myView=[[UIView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64)];
        _myView.backgroundColor=[UIColor whiteColor];
        [self.view addSubview:_myView];
        
        
        UILabel *lab=[[UILabel alloc]init];
        lab.bounds=CGRectMake(0, 0, 200, 30);
        lab.center=CGPointMake(self.view.center.x, self.view.center.y);
        lab.text=@"亲，你还没有收到消息哟!";
        lab.font=[UIFont systemFontOfSize:13];
        lab.textColor=[UIColor blackColor];
        lab.textAlignment=NSTextAlignmentCenter;
        //lab.backgroundColor=[UIColor grayColor];
        [_myView addSubview:lab];
        
        //为收到消息图片
        UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(lab.frame.origin.x+30, lab.frame.origin.y-155, 140, 155)];
        imgView.image=[UIImage imageNamed:@"receiveMessage_no"];
        [_myView addSubview:imgView];
        
        
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//代理
-(void)gotoXiangQing:(NSString *)topicId
{
    TieBaXiangQingViewController *vc=[[TieBaXiangQingViewController alloc]init];
    //vc.arr=arr;
    vc.topic_id=[topicId integerValue];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden=NO;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
